package com.customization.api.e9sso.cmd;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.hrm.web.HrmSystemInfoAction;
import com.customization.commons.Console;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.workflow.webservices.WorkflowServiceImpl;

import java.util.HashMap;
import java.util.Map;

public class GetHrmSapCompanyListCmd extends AbstractCommonCommand<Map<String,Object>> {


    private String appid;
    public GetHrmSapCompanyListCmd(User user, Map<String,Object> params) {
        this.user = user;
        this.params = params;
        appid=Util.null2String(params.get("appid"));
    }


    @Override
    public BizLogContext getLogContext() {
        return null;
    }


    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Console.log("输入参数params:"+params.toString());
        Map<String, Object> apidatas = new HashMap<String, Object>();
        apidatas.put("status",true);
        apidatas.put("msg","查询成功!");
        RecordSet rs = new RecordSet();

        String sqlwhere="";
        String lastmoddate=Util.null2String(params.get("lastmoddate"));
        if(!lastmoddate.equals("")){
            sqlwhere=" and lastmoddate>= '"+lastmoddate+"'";
        }
        boolean b=rs.execute("select id,workcode,companycode,costcenter from hrmresource where  1=1 "+sqlwhere);
        if(!b) {
            apidatas.put("status",b);
            apidatas.put("msg", "查询失败!");
            return apidatas;
        }
        JSONArray  jsonArray=new JSONArray();

        while (rs.next()){
            JSONObject json=new JSONObject();
            json.put("id",rs.getString("id"));
            json.put("workcode",rs.getString("workcode"));
            json.put("companycode",rs.getString("companycode"));
            json.put("costcenter",rs.getString("costcenter"));
            jsonArray.add(json);
        }


        apidatas.put("data",jsonArray);


        return apidatas;
    }
}
